package cn.edu.zafu.bigdata.x.huangxihao202211080211;

import java.util.Arrays;
import java.util.List;

class GenericUtil {
    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            throw new IllegalArgumentException("List cannot be null or empty");
        }

        T max = list.get(0);
        for (T element : list) {
            if (element.compareTo(max) > 0) {
                max = element;
            }
        }
        return max;
    }
}

public class TestFindMax11 {
    public static void main(String[] args) {
        // 测试整数列表
        List<Integer> intList = Arrays.asList(1, 3, 5, 2, 4);
        Integer maxInt = GenericUtil.findMax(intList);
        System.out.println("最大整数是: " + maxInt);

        // 测试字符串列表
        List<String> strList = Arrays.asList("apple", "banana", "cherry");
        String maxStr = GenericUtil.findMax(strList);
        System.out.println("最大字符串是: " + maxStr);
    }
}
